#include<iostream>
#include<unordered_map>
using namespace std;

class Solution {
public:
    bool canConstruct(string ransomNote, string magazine) 
    {
        unordered_map<char,int> hash;
        for(auto ch:magazine)
        {
            hash[ch]++;
        }
        for(auto ch:ransomNote)
        {
            if(hash.find(ch)!=hash.end())
            {
                if(hash[ch]==0)
                {
                    return false;
                }
                else
                {
                    hash[ch]--;
                }
            }
            else
            {
                return false;
            }
        }
        return true;
    }
};